package com.ytd.smartcanteen.weighting.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.ytd.common.util.LogUtil;
import com.ytd.smartcanteen.weighting.MainActivity;

import java.util.Objects;


public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        switch (Objects.requireNonNull(intent.getAction())) {
            case Intent.ACTION_BOOT_COMPLETED://开机广播
                LogUtil.e("----------------开机----------------------");
                try {
                    Intent intent2 = new Intent(context, MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent2);
                } catch (Throwable e) {
                    LogUtil.e("开机广播 error：" + e.getMessage());
                    try {
                        Intent intent2 = new Intent(context, MainActivity.class);
                        context.startActivity(intent2);
                    } catch (Throwable ex) {
                        LogUtil.e("开机广播 error2：" + e.getMessage());
                    }
                }
                break;
            case Intent.ACTION_SHUTDOWN://关机广播
                LogUtil.e("----------------关机----------------------");
                break;

        }
    }
}
